﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace ZeroBugBounce.Missive
{
	public class TimeoutHandler<T> : LambdaHandler<T>
	{
		public TimeoutHandler()
		{
			Topic = Topic.DefaultTopic;
			DispatchMode = DispatchMode.AsyncLongRunning;
		}

		public TimeoutHandler(TimeSpan timeout, Action<HandlerContext<T>> method, 
							  Action<HandlerContext<T>> timeoutMethod)
		{
			Timeout = timeout;
			Method = method;
			TimeoutMethod = timeoutMethod;
			DispatchMode = DispatchMode.AsyncLongRunning;
		}

		public override void Handle(HandlerContext<T> context)
		{
			Method(context);
		}

		public TimeSpan Timeout { get; set; }
		public Action<HandlerContext<T>> TimeoutMethod { get; set; }

		protected Thread ExecutingThread;
	}
}
